package webapp;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class AdminPanel
 */
public class AdminPanel extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminPanel() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("We are in Service method of AdminPanel");
		PrintWriter out=response.getWriter();  
		
		HttpSession session=request.getSession(false); 
		String un = (String) session.getAttribute("name");
        if(un!=null){
		
		String action = request.getParameter("action");
		
		System.out.println(session.getAttribute("name"));
				if ("Register".equals(action)) {
		    // Invoke FirstServlet's job here.
						response.sendRedirect("Register.jsp");
				}else if ("Delete".equals(action)) {
		    // Invoke SecondServlet's job here.
			response.sendRedirect("AdminDelete.jsp");
				}
		}else{  
			out.print("Please login first");    
            request.getRequestDispatcher("index.jsp").include(request, response);  
        } 
        
	}
}
